﻿Imports MySql.Data.MySqlClient
Public Class dDiagnostico
    Private con As MySqlConnection
    Private comando As MySqlCommand
    Dim lector As MySqlDataReader
    Private lector2 As MySqlDataAdapter
    Private data As DataSet
    ' CLASE PARA CARGAR DATOS de LA BD
    Public Function CargarMysql(ByVal Campo As String) As ArrayList
        Dim resultado As ArrayList
        resultado = New ArrayList
        con = Conexion.open()
        comando = New MySqlCommand("Select * from diagnosticos where codigo_diagnostico='" & Campo & "'", con)
        lector = comando.ExecuteReader
        If lector.Read() = True Then
            resultado.Add(lector.GetString(0))
            resultado.Add(lector.GetString(1))
            resultado.Add(lector.GetString(2))
        End If
        Conexion.Close(con)
        lector.Close()
        Return resultado
    End Function
    'guardar la informacion
    Public Sub GuardarMysql(ByVal Codigo As String, ByVal Nombre As String, ByVal Estado As String)
        Dim Resultado As ArrayList
        Resultado = CargarMysql(Codigo)
        con = Conexion.open()
        If Resultado.Count <> 0 Then
            'realizamos la actualizacion
            comando = New MySqlCommand("UPDATE diagnosticos SET nombre_diagnostico='" & Nombre & "' " _
                                       & "where codigo_diagnostico='" & Codigo & "'", con)
            comando.ExecuteNonQuery()
        Else
            'realizamos l insercion
            comando = New MySqlCommand("insert into diagnosticos(codigo_diagnostico, nombre_diagnostico, estado) " _
                                       & "values('" & Codigo & "','" & Nombre & "','A')", con)
            comando.ExecuteNonQuery()
        End If
        Conexion.Close(con)
        'comando = New MySqlCommand("Inser  * from diagnosticos where codigo_diagnostico like '" & Campo & "%" & "'", con)
    End Sub
    'devolver consulta Diagnostico
    Public Function ConsultarMysql(ByVal Campo As String) As DataSet
        Dim Resultado As ArrayList
        Resultado = New ArrayList
        con = Conexion.open()
        comando = New MySqlCommand("Select * from diagnosticos where codigo_diagnostico like '" & Campo & "%" & "'", con)
        lector2 = New MySqlDataAdapter(comando)
        data = New DataSet
        lector2.Fill(data)
        Conexion.Close(con)
        Return data
    End Function
End Class
